<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>会员注册</title>
  <meta content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0" name="viewport"/>
  <meta content="yes" name="apple-mobile-web-app-capable"/>
  <meta content="black" name="apple-mobile-web-app-status-bar-style"/>
  <meta content="telephone=no" name="format-detection"/>
  <script src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
  <script src="__STATIC__/plugs/layui/lay/modules/layer.js"></script>
</head>
<body>
  <form action="javascript:;" method="post">
	昵称：<input type="text" name="nickname" value="" ><br/>
	绑定手机：<input type="text" name="mobile" value="" ><br/>
	验证码：<input type="text" name="verify_code" value=""><br/>
	<input type="button"  value="点击获取验证码" onclick="get_verify_code()">
	密码：<input type="password" name="password" value=""><br/>
	确认密码：<input type="password" name="repassword" value=""><br/>
	<input type="button"   value="提交" onclick="checkform();">
    <input type="text" name="sharer" value="{$sharer}">
</form>
</body>
</html>
<script>
  /**
   * 	获取短信验证码
   * 	@param  $mobile  绑定手机
   */
  function get_verify_code(){
      var mobile = $('input[name=mobile]').val();   //注册手机号
      var reg = /^1[34578]\d{9}$/;
      if($('input[name=mobile]').val() == ''){
          alert("请输入手机号");
//          layer.msg('请输入手机号',{icon: 2,time: 1000},function(){});
          return false;
      }
      if(!reg.test($('input[name=mobile]').val())){
          alert("手机号格式错误");
//          layer.msg('手机号格式错误',{icon: 2,time: 1000},function(){});
          return false;
      }
      $.post("{:url('Register/get_msg_code')}",
          {mobile:mobile},
          function(data){
              if(data.code == 1){
                  alert('发送成功');
//                  layer.msg(data.msg, {
//                      icon: 1,
//                      time: 1000 //2秒关闭（如果不配置，默认是3秒）
//                  }, function () {
//
//                  });
              }else{
                  alert(data.msg);
//                  layer.msg(data.msg, {
//                      icon: 2,
//                      time: 1000 //2秒关闭（如果不配置，默认是3秒）
//                  }, function () {
//
//                  });
              }
          }
      );
  }
  /**
   * 检查表单信息
   */
  function checkform(){
      var reg = /^[0-9a-zA-Z_]{6,16}$/;
      var mobile = $('input[name=mobile]').val();
      var nickname = $('input[name=nickname]').val();
      var password = $('input[name=password]').val();
      var repassword = $('input[name=repassword]').val();
      var verify_code = $('input[name=verify_code]').val();
      var sharer = $('input[name=sharer]').val();

      if($('input[name=nickname]').val() == ''){
          layer.msg('请填写昵称',{icon: 2,time: 1000},function(){});
          return false;
      }
      if($('input[name=mobile]').val() == ''){
          layer.msg('请输入手机号',{icon: 2,time: 1000},function(){});
          return false;
      }
      if(!reg.test($('input[name=mobile]').val())){
          layer.msg('手机号格式错误',{icon: 2,time: 1000},function(){});
          return false;
      }
      if($('input[name=password]').val() == ''){
          layer.msg('请填写登录密码',{icon: 2,time: 1000},function(){});
          return false;
      }
      if($('input[name=verify_code]').val() == ''){
          layer.msg('请填写验证码',{icon: 2,time: 1000},function(){});
          return false;
      }

      $.post("{:url('Register/post_register')}",
          {mobile:mobile,nickname,password:password,repassword:repassword,verify_code:verify_code,sharer:sharer},
          function(data){
              if(data.code == 1){
                  alert('注册成功');
                  window.location.href = "{:url('Index/index')}";
              }else{
                  alert(data.msg);
              }
          }

      );
      return true;
  }
</script>